remotemanager.connection.cmd module

remotemanager.connection.cmd.detect_locale_error(stderr)[source]

Given a stderr output string stderr, will regex search for the locale errors

Parameters:

stderr – stderr text

Returns:

True if the error appears to be a locale issue

Return type:

bool

class remotemanager.connection.cmd.CMD(cmd: str, asynchronous: bool = False, stdout: str = None, stderr: str = None, stream: bool = False, timeout: int = 5, max_timeouts: int = 3, raise_errors: bool = True, force_file: bool = False, verbose: None | int | bool | Verbosity = None)[source]

This class stores a command to be executed, and the returned stdout, stderr

Parameters:
  • cmd (str) – command to be executed

  • asynchronous (bool) – execute commands asynchronously defaults to False

  • stdout (str) – optional file to redirect stdout to

  • stderr (str) – optional file to redirect stderr to

  • stream (bool) – enables output streaming if True

  • timeout (int) – time to wait before issuing a timeout

  • max_timeouts (int) – number of times to attempt communication in case of a timeout

  • force_file (bool) – always use the fexec method if True

property verbose: Verbosity

Verbose property

property sent: str

The command passed at initialisation

property cmd: str

Alias for init command

property asynchronous: bool

True if commands are to be executed asynchronously

property is_redirected: bool

True if the cmd is redirected to a file

property stdout: str

Directly returns the stdout from the cmd execution. Attempts to communicate with the subprocess in the case of an async run.

Returns None if the command has not been executed yet.

Returns (str):

the stdout from the command execution

property stderr: str

Directly returns the stderr from the cmd execution. Attempts to communicate with the subprocess in the case of an async run.

Returns None if the command has not been executed yet.

Returns (str):

the stdout from the command execution

property pwd: str

Present working directory at command execution

Returns None if the command has not been executed yet.

Returns (str):

working dir of command execution

property whoami: str

Present user at command execution

Returns None if the command has not been executed yet.

Returns (str):

username who executed the command

property pid: int

The Process ID of the spawned process

Returns None if the command has not been executed yet.

Returns (int):

the PID of the spawned shell for this command

property returncode: [<class 'int'>, None]

Attempt to retrieve the returncode of the subprocess. This call will not disturb an asynchronous run, returning None

Returns (int, None):

The exit status of the subprocess, None if it is still running. None otherwise.

property is_finished: bool

Returns True if this command has finished execution. This will NOT talk to the process, as to not disturb async runs, so will always return False in those instances

Returns (bool):

True if the command has completed

property succeeded: [None, <class 'bool'>]

True if the command successfully executed

Returns:

None if not finished, True if returncode is 0

exec(verbose: None | int | bool | Verbosity = None) None[source]

Executes the command, storing execution info and in the case of a non-async run; returned values

Returns:

None

communicate(use_cache: bool = True, ignore_errors: bool = None, verbose: None | int | bool | Verbosity = None) dict[source]

Communicates with the subprocess, returning the stdout and stderr in a dict

Parameters:
  • use_cache (bool) – use cached value if it is available

  • ignore_errors (bool) – do not raise error regardless of base setting

Returns (dict):

{‘stdout’: stdout, ‘stderr’: stderr}

kill(pid: int = None, verbose: None | int | bool | Verbosity = None) None[source]

Kill the process associated with this command, if one exists

Returns:

None